package cn.iocoder.yudao.module.infra.repository.mybatis.dao.codegen;

import cn.iocoder.yudao.common.pojo.PageResult;
import cn.iocoder.yudao.core.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.core.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.infra.controller.admin.codegen.vo.table.CodegenTablePageReqVO;
import cn.iocoder.yudao.module.infra.repository.mybatis.domain.codegen.CodegenTable;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface CodegenTableMapper extends BaseMapperX<CodegenTable> {

    default CodegenTable selectByTableNameAndDataSourceConfigId(String tableName, Long dataSourceConfigId) {
        return selectOne(CodegenTable::getTableName, tableName,
                CodegenTable::getDataSourceConfigId, dataSourceConfigId);
    }

    default PageResult<CodegenTable> selectPage(CodegenTablePageReqVO pageReqVO) {
        return selectPage(pageReqVO, new LambdaQueryWrapperX<CodegenTable>()
                .likeIfPresent(CodegenTable::getTableName, pageReqVO.getTableName())
                .likeIfPresent(CodegenTable::getTableComment, pageReqVO.getTableComment())
                .likeIfPresent(CodegenTable::getClassName, pageReqVO.getClassName())
                .betweenIfPresent(CodegenTable::getCreateTime, pageReqVO.getCreateTime()));
    }

    default List<CodegenTable> selectListByDataSourceConfigId(Long dataSourceConfigId) {
        return selectList(CodegenTable::getDataSourceConfigId, dataSourceConfigId);
    }

}
